import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

export function middleware(request: NextRequest) {
    // Assume a "Cookie:nextjs=fast" header to be present on the incoming request
    // Getting cookies from the request using the `RequestCookies` API
    let cookieAccount = request.cookies.get('sjhm')
    // console.log(cookieAccount)
    //   console.log(cookieAccount) // => { name: 'nextjs', value: 'fast', Path: '/' }
    const allCookies = request.cookies.getAll()
    // console.log(allCookies) // => [{ name: 'nextjs', value: 'fast' }]
    const response = NextResponse.next()
    let date7Days = new Date(new Date().getTime() + (7 * 24 * 60 * 60 * 1000));
    for (let ii = 0; ii < allCookies.length; ii++) {
        response.cookies.set({
            name: allCookies[ii].name,
            value: allCookies[ii].value,
            path: '/',
            expires: date7Days
        })
    }
    // if (!cookieAccount) {
    //     return NextResponse.redirect('https://www.xsjxkt.com/qd/dl/login')
    // }
    return response
}